package com.weilai.service.serviceImpl;

import com.weilai.dao.PostsDao;
import com.weilai.dao.ReportInfoDao;
import com.weilai.dao.UserDao;
import com.weilai.domain.Posts;
import com.weilai.domain.ReportInfo;
import com.weilai.service.ReportInfoService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

@Service
public class ReportInfoServiceImpl implements ReportInfoService {
    @Autowired
    private ReportInfoDao reportInfoDao;
    @Autowired
    private UserDao userDao;
    @Autowired
    private PostsDao postsDao;


    @Override
    public List<ReportInfo> selectAllReportedInfo() {
        List<ReportInfo> reportInfos = reportInfoDao.selectAllReportedInfo();
        for(ReportInfo reportInfo:reportInfos){

            Posts posts = postsDao.selectById(reportInfo.getPostId());
            reportInfo.setContent(posts.getContent());

        }
        return reportInfos;
    }

    @Override
    public List<ReportInfo> selectReportedInfo() {
        List<ReportInfo> reportInfos = reportInfoDao.selectReportedInfo();
        for(ReportInfo reportInfo:reportInfos){

            Posts posts = postsDao.selectById(reportInfo.getPostId());
            reportInfo.setContent(posts.getContent());
        }
        return reportInfos;
    }

    @Transactional
    @Override
    public void reportSuccessfully(int id) {
        reportInfoDao.reportSuccessfully(id);
        reportInfoDao.updateReportSuccessfully(id);
    }

    @Override
    public ReportInfo selectReportedInfoById(int id) {
        ReportInfo reportInfo = reportInfoDao.selectReportedInfoById();
        return reportInfo;
    }


    @Override
    public void reportFail(int id) {
        reportInfoDao.reportFail(id);
    }

    @Override
    public void reportOthers(ReportInfo reportInfo) {
       reportInfoDao.reportOthers(reportInfo);
    }

}
